import request from '@/utils/request'
import type { Response } from '@/utils/type'
import type {
  ProjectRecords,
  queryProjectParams,
} from '@/api/back-management/complete-community-project/interface'
import type { PageDataList as PageList } from '@/utils/type'

interface PageDataList<T> {
  total: number
  records: T[]
}

/**
 * 获取完整社区项目列表
 *
 * @param {queryProjectParams} params 查询参数
 * @param {string | number} pageSize 分页大小
 * @param {string | number} pageIndex 当前页码
 *
 */
export const queryProjectList = (
  params: queryProjectParams,
  pageSize: string | number,
  pageIndex: string | number
): Promise<Response<PageDataList<ProjectRecords>>> => {
  return request(`/residential/project/query/${pageSize}/${pageIndex}`, {
    method: 'POST',
    data: params,
  })
}
/**
 * 查询项目申报详情
 *
 * @param {string} basicId 基本情况id
 *
 */
export const queryProjectDetail = (basicId: string): Promise<Response<any>> => {
  return request(`/residential/project/get/${basicId}`, {
    method: 'GET',
  })
}
/**
 * 查看社区范围
 *
 * @param {string | number} communityId 社区id可多个（用‘,’隔开）
 *
 */
export const queryProjectRange = (
  communityId: string | number
): Promise<Response<PageDataList<ProjectRecords>>> => {
  return request(`/residential/project/getByRange?communityId=${communityId}`, {
    method: 'POST',
    data: { communityId: communityId },
  })
}
/**
 * 查看社区范围
 *
 * @param {string | number} communityId 社区id可多个（用‘,’隔开）
 *
 */
export const queryProjectGetNumber = (
  communityId: string | number
): Promise<Response<PageDataList<ProjectRecords>>> => {
  return request(`/residential/project/getNumber?communityId=${communityId}`, {
    method: 'POST',
    data: { communityId: communityId },
  })
}
/**
 * 更新项目状态
 *
 * @param {basicId: string,projectState: string | number} params 请求参数
 *
 */
export const updateProjectProjectStatus = (params: {
  basicId: string
  projectState: string | number
}): Promise<Response<string | null>> => {
  return request(`/residential/project/updateProject`, {
    method: 'POST',
    params,
  })
}
/**
 * 更新审核状态
 *
 * @param {string} basicId 基本情况id
 * @param {string | number} auditState 审核状态
 *
 */
export const updateProjectAuditStatus = (
  basicId: string,
  auditState: string | number,
  reviewComments: string
): Promise<Response<PageDataList<ProjectRecords>>> => {
  return request(
    `/residential/project/updateAudit?basicId=${basicId}&auditState=${auditState}&reviewComments=${reviewComments}`,
    {
      method: 'POST',
      data: {
        basicId: basicId,
        auditState: auditState,
        reviewComments: reviewComments,
      },
    }
  )
}
/**
 * 项目申报删除
 *
 * @param {string} basicId 基本情况id
 *
 */
export const deleteProject = (
  basicId: string
): Promise<Response<PageDataList<ProjectRecords>>> => {
  return request(`/residential/project/delete/${basicId}`, {
    method: 'DELETE',
  })
}
/**
 * 项目申报新增
 *
 * @param {any} params 新增参数
 *
 */
export const addProject = (
  params: any
): Promise<Response<string | undefined>> => {
  return request(`/residential/project/add`, {
    method: 'POST',
    data: params,
  })
}
/**
 * 项目申报更新
 *
 * @param {any} params 新增参数
 *
 */
export const updateProject = (
  params: any
): Promise<Response<string | undefined>> => {
  return request(`/residential/project/update`, {
    method: 'POST',
    data: params,
  })
}

/**
 * 查询最新月报信息
 *
 * @param {string} basicId 基本情况id
 *
 */
export const queryProjectMonthReport = (
  basicId: string
): Promise<Response<any>> => {
  return request(`/residential/month/getByNew?basicId=${basicId}`, {
    method: 'POST',
  })
}

/**
 * 获取月报信息列表
 *
 * @param {any} params 查询参数
 *
 */
export const queryMonthReportList = (
  params: any
): Promise<Response<PageList<any>>> => {
  return request(`/residential/month/query`, {
    method: 'POST',
    data: params,
  })
}

/**
 * 查询月报信息详情
 *
 *
 * @param params
 */
export const queryMonthReportDetail = (params: any): Promise<Response<any>> => {
  return request(`/residential/month/get`, {
    method: 'POST',
    data: params,
  })
}

/**
 * 更新月报信息详情
 *
 *
 * @param params
 * @param monthId
 */
export const updateMonthReport = (
  params: any,
  monthId: string
): Promise<Response<any>> => {
  return request(`/residential/month/update/${monthId}`, {
    method: 'POST',
    data: params,
  })
}
/**
 * 查询上月月报信息
 *
 *
 * @param params
 */
export const preMonthGetLast = (params: any): Promise<Response<any>> => {
  return request(
    `/residential/month/getLast?monthId=${params.monthId}&basicId=${params.basicId}`,
    {
      method: 'POST',
      data: params,
    }
  )
}
/**
 * 查询当月月月报信息
 *
 *
 * @param params
 */
export const currentMonthGetThis = (params: any): Promise<Response<any>> => {
  return request(`/residential/month/getThis?monthId=${params.monthId}`, {
    method: 'POST',
    data: params,
  })
}
/**
 * 查询当月月月报阶段信息
 *
 *
 * @param params
 */
export const currentMonthGetStage = (params: any): Promise<Response<any>> => {
  return request(`/residential/month/getStage`, {
    method: 'POST',
    params,
  })
}

/**
 * 查询项目名称
 *
 *
 * @param params
 */
export const monthGetProjectName = (params: any): Promise<Response<any>> => {
  return request(`/residential/month/getProjectName`, {
    method: 'GET',
    params,
  })
}
/**
 * 新增月报信息
 *
 *
 * @param params
 */
export const monthAdd = (params: any): Promise<Response<any>> => {
  return request(`/residential/month/add`, {
    method: 'POST',
    data: params,
  })
}
